package com.tanhua.server.controller;

import com.tanhua.domain.db.UserInfo;
import com.tanhua.server.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("users")
public class UserInfoController {
    @Autowired
    private UserService userService;
    
    /**
     * 接口名称：用户资料 - 读取
     * 接口路径：GET/users
     * 需求分析：根据用户id查询用户详情
     * 控制器：处理请求、接收请求参数、调用service、返回
     */
    @GetMapping
    public ResponseEntity<Object> findUserInfoById(Long userID, Long huanxinID) {
        return userService.findUserInfoById(userID, huanxinID);
    }
    
    /**
     * 接口名称：用户资料 - 保存
     * 接口路径：PUT/users
     * 需求分析：修改用户详情  tb_user_info
     */
    @PutMapping
    public ResponseEntity<Object> updateUserInfo(@RequestBody UserInfo userInfo) {
        return userService.updateUserInfo(userInfo);
    }
    
    /**
     * 接口名称：互相喜欢，喜欢，粉丝
     * 接口路径：GET/users/counts
     */
    @GetMapping("counts")
    public ResponseEntity<Object> queryCounts() {
        return userService.queryCounts();
    }
    
    /**
     * 接口名称：互相喜欢、喜欢、粉丝、谁看过我  (列表)
     * 接口路径：GET/users/friends/:type
     */
    @GetMapping("friends/{type}")
    public ResponseEntity<Object> queryUserLikeList(
            @PathVariable("type") Integer type,
            @RequestParam(defaultValue = "1") Integer page,
            @RequestParam(defaultValue = "10") Integer pagesize) {
        return userService.queryUserLikeList(type, page, pagesize);
    }
    
    /**
     * 接口名称：粉丝 - 喜欢
     * 接口路径：POST/users/fans/:uid
     */
    @PostMapping("fans/{uid}")
    public ResponseEntity<Object> fanLike(
            @PathVariable("uid") Long likeUserId) {
        return userService.fanLike(likeUserId);
    }
    
    
}
